package com.atguigu.jdbc2;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

/**
 * @author 798133716@qq.com
 * @create 2021-02-26 20:56
 */
public class BaseDao<T> {
    private QueryRunner qr = new QueryRunner();
    public int update(Connection connection,String sql,Object... obj){

        try {
            return qr.update(connection,sql,obj);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }
    }
    public List<T> query(Connection connection, String sql, Class clazz,Object...obj){
        List<T> query = null;
        try {
            query = qr.query(connection, sql, new BeanListHandler<T>(clazz), obj);
            return query;
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }
    }
}
